<template>
  <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
    <el-form-item label="技术点名称" prop="name">
      <el-input v-model="ruleForm.name" />
    </el-form-item>
    <el-form-item label="难度等级" prop="level">
      <el-rate style="margin-top:8px;" v-model="ruleForm.level" />
    </el-form-item>
    <el-form-item label="排序" prop="sort">
      <el-input v-model="ruleForm.sort" type='number' />
    </el-form-item>
    <el-form-item label="详细描述">
      <el-input v-model="ruleForm.description" :autosize="{ minRows: 2, maxRows: 4}" type="textarea" placeholder="请输入详细描述" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: 'SkillEdit',
  props: {
    editId: {
      type: Number,
      default: undefined
    },
    rank: {
      type: Number,
      default: undefined
    },
    parentid: {
      type: Number,
      default: undefined
    }
  },
  data() {
    return {
      ruleForm: {
        id: '',
        name: '',
        level: 1,
        parentId: 0,
        rank: 1,
        sort: 0,
        description: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入方向名称', trigger: 'blur' },
          { min: 1, max: 10, message: '长度在 1 到 20 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    if (this.editId !== undefined) {
      this.ruleForm.id = this.editId
      this.get('/skill/getone', (result) => {
        this.extend(this.ruleForm, result.data)
        delete this.ruleForm['children']
      }, { id: this.editId })
    } else {
      this.reset()
      this.ruleForm.id = ''
      this.parentid !== undefined ? this.ruleForm.parentId = this.parentid : this.ruleForm.parentId = 0
      this.rank !== undefined ? this.ruleForm.rank = this.rank : this.ruleForm.rank = 1
      console.log(this.parentid)
    }
  },
  methods: {
    reset() {
      this.ruleForm = {
        id: '',
        name: '',
        level: 1,
        sort: 0,
        description: ''
      }
    },
    onSubmit() {
      this.post('/skill/save', 'ruleForm', result => {
        this.$emit('getlist')
        this.$emit('update:dialogFormVisible', false)
      }, this.ruleForm)
    }
  }
}
</script>
<style scoped>

</style>
